package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyGroupGetPageDTO;
import com.itlong.cloud.POJO.PO.PropertyGroupPO;
import com.itlong.cloud.property.service.IPropertyGroupService;
import com.itlong.cloud.user.property.IPropertyGroupServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业-部门业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/10/17
 */
@RestController
public class PropertyGroupServiceResource implements IPropertyGroupServiceClient{


    @Autowired
    IPropertyGroupService iPropertyGroupService;

    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @return page
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @RequestMapping(path = "/property/system/group/getPage")
    @Override
    public Page<PropertyGroupPO> getPage(@RequestBody PropertyGroupGetPageDTO pageDTO) throws Exception {
        return iPropertyGroupService.getPage(pageDTO);
    }

    /**
     * <desc>
     *      保存部门
     * </desc>
     *
     * @param propertyGroupPO
     * @return
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @Override
    @RequestMapping(path = "/property/system/group/save")
    public Integer save(@RequestBody PropertyGroupPO propertyGroupPO) throws Exception {
        return iPropertyGroupService.save(propertyGroupPO);
    }

    /**
     * <desc>
     *      更新部门
     * </desc>
     *
     * @param propertyGroupPO
     * @return
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @Override
    @RequestMapping(path = "/property/system/group/updateGroup")
    public Integer update(@RequestBody PropertyGroupPO propertyGroupPO) throws Exception {
        return iPropertyGroupService.update(propertyGroupPO);
    }

    /**
     * <desc>
     *      根据id查询部门
     * </desc>
     *
     * @param propertyGroupPO
     * @return
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @Override
    @RequestMapping(path = "/property/system/group/getOne")
    public PropertyGroupPO getOne(@RequestBody PropertyGroupPO propertyGroupPO){
        return iPropertyGroupService.getOne(propertyGroupPO);
    }

    /**
     * <desc>
     *      禁用或启用部门
     * </desc>
     *
     * @param propertyGroupPO 部门实体
     * @return
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @Override
    @RequestMapping(path = "/property/system/group/banOrUse")
    public Integer banOrUse(@RequestBody PropertyGroupPO propertyGroupPO) throws Exception {
        return iPropertyGroupService.update(propertyGroupPO);
    }

    /**
     * <desc>
     *       部门分配人员
     * </desc>
     *
     * @param groupId    部门id
     * @param allotUsers    需要分配的人员id 多个，号分隔
     * @param userIds 当前列表所有人员id 多个，号分隔
     * @return sql执行行数
     * @author Biao.R
     * @createDate 2017/10/17
     */
    @RequestMapping(path = "/property/system/group/saveGroupUsers")
    @Override
    public Integer saveGroupUsers(
                @RequestParam("groupId") String groupId,
                @RequestParam("allotUsers") String allotUsers,
                @RequestParam("userIds") String userIds) {
        return iPropertyGroupService.saveGroupUsers(groupId,allotUsers,userIds);
    }

    /**
     * <desc>
     *      根据字段查询部门
     * <desc/>
     * @param   params  查询参数
     * @return List<PropertyGroupPO>    返回对象集合
     * @author Biao.R
     * @createDate 2017/10/18
     */
    @PostMapping(path = "/property/system/group/getByFeilds")
    @Override
    public List<PropertyGroupPO> getByFeilds(@RequestBody Map<String, Object> params) {
        return iPropertyGroupService.getByFeilds(params);
    }


}
